<?php
namespace Home\Controller;
use Home\Controller\BaseController;
// +----------------------------------------------------------------------
// | Date:2017年1月11日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class MyHistoryController extends BaseController{
    
    protected $model = '';
    public function _initialize(){
        parent::_initialize();
        $this->model = D('ProductHistory');
        $this->assign('showSearchbar','hide');//隐藏顶部的搜索框
    }
    
    public function index(){
        
        $model = I('model',1);
        $search_title = I('title');
        switch ($model){
            case 1 :
                $daystr = date('Y-m-d 00:00:00');
                $dayend = date('Y-m-d 23:59:59');
                break;//今天
            case 2 :
                $daystr = date('Y-m-d 00:00:00',strtotime("-1 day"));
                $dayend = date('Y-m-d 23:59:59',strtotime("-1 day"));
                break;//昨天
            case 3 :
                $daystr = date('Y-m-d 00:00:00',strtotime("last Monday"));
                $dayend = date('Y-m-d 23:59:59',strtotime("next Sunday"));
                break;//一周内
        }
        
        if ($model == 4) {
            $where['created_time'] = ['lt',date('Y-m-d 00:00:00',strtotime("last Monday"))];
        }else{
            $where['created_time'] = ['between',[$daystr,$dayend]];
        }
        
        $where['uid'] = $this->uid;
        $field = 'his.id as his_id,pro.id as pro_id,summary,title,image_id,t_lx,t_jx';
        $order = 'his.created_time desc';
        $count = $this->model->alias('his')->join('LEFT JOIN __PRODUCT__ pro ON pro.id = his.pro_id')->where($where)->count();
        
        $page = new \Think\Page($count,20);
        
        $showPage = $page->show();
        $list =  $this->model->alias('his')
        ->join('LEFT JOIN __PRODUCT__ pro ON pro.id = his.pro_id')
        ->where($where)
        ->order($order)
        ->limit($page->firstRow, $page->listRows)
        ->field($field)
        ->select();
        
        $list = D('Product')->getCover($list);//拼接封面图
        $this->assign('curmodel',$model);
        $this->assign("page",$showPage);
        $this->assign("list",$list);       
        $this->display();    
    }
    

}